from django.conf import settings
from django.conf.urls.defaults import patterns, url, include
from django.contrib import admin
from django.views.generic.simple import direct_to_template
from coresales.admin import ClientAdmin, OrderAdmin, PhotoAdmin, CatalogAdmin, \
    CategoryAdmin, ProductAdmin, CartAdmin, OrderProductAdmin,\
    PriceIncrementAdmin
from coresales.mappings import FlatpageSitemap, CatalogSitemap, \
    CategorySitemap, ItemSitemap
from coresales.models import Client, Order, Photo, Catalog, Category, Product, \
    Cart, ProductDetail, ProductAttribute, OrderProduct, PriceIncrement
from coresales.rss import LatestEntriesFeed, AtomSiteNewsFeed

admin.autodiscover()
admin.site.register(Client,ClientAdmin)
admin.site.register(Order,OrderAdmin)
admin.site.register(Photo,PhotoAdmin)
admin.site.register(Catalog,CatalogAdmin)
admin.site.register(Category,CategoryAdmin)
admin.site.register(Product,ProductAdmin)
admin.site.register(Cart,CartAdmin)
admin.site.register(OrderProduct,OrderProductAdmin)
admin.site.register(ProductDetail)
admin.site.register(ProductAttribute)
admin.site.register(PriceIncrement,PriceIncrementAdmin)

sitemaps = {
    'flatpages': FlatpageSitemap,
    'catalogos' : CatalogSitemap,
    'categorias': CategorySitemap,
    'articulos' : ItemSitemap,
}


urlpatterns = patterns('',
    #Searchers
    url(r'^catalogo_(?P<catalog_slug>[-\w]+)', 'coresales.views.listCatalog', name='listCatalog'),
    url(r'^categoria_(?P<category_slug>[-\w]+)__catalogo_(?P<catalog_slug>[-\w]+)', 'coresales.views.listCategory',name='listCategory'),
    url(r'^articulo_(?P<item_slug>[-\w]+)__categoria_(?P<category_slug>[-\w]+)__catalogo_(?P<catalog_slug>[-\w]+)', 'coresales.views.detailItem',name='detailItem'),
    url(r'^searchAll/', 'coresales.views.searchAll', name='searchAll'),
    url(r'^search/$', 'coresales.views.search'),
    #Home
    url(r'^$', 'coresales.views.index'),

    #Shopping cart
    url(r'^cart/list$', 'coresales.views.listCart',name='listCart'),
    url(r'^cart/detail/(?P<cart_code>\w+)/$', 'coresales.views.cartDetail',name='cartDetail'),
    url(r'^cart/add/(?P<item_code>\d+)/(?P<count>\d+)/$', 'coresales.views.addItemCart',name='addItemCart'),
    url(r'^cart/(?P<cart_code>\w+)/remove/(?P<item_code>\d+)/$', 'coresales.views.removeItemCart',name='removeItemCart'),
    url(r'^addOrder/(?P<cart_code>\w+)/$', 'coresales.views.addOrder',name='addOrder'),
    url(r'^addOrder/(?P<cart_code>\w+)/confirmOrder/$',  'coresales.views.confirmOrder',name='confirmOrder'),
    #Login and registration
    url(r'^activate/(?P<activation_key>\w+)/$','activate',name='registration_activate'),
    url(r'^login/$', 'django.contrib.auth.views.login',{'template_name': 'registration/login.html'},name='auth_login'),
    url(r'^logout/$','django.contrib.auth.views.logout',{'template_name': 'registration/logout.html'},name='auth_logout'),
    url(r'^password/change/$','django.contrib.auth.views.password_change',name='auth_password_change'),
    url(r'^password/change/done/$','django.contrib.auth.views.password_change_done',name='auth_password_change_done'),
    url(r'^password/reset/$','django.contrib.auth.views.password_reset',name='auth_password_reset'),
    url(r'^password/reset/confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$','django.contrib.auth.views.password_reset_confirm',name='auth_password_reset_confirm'),
    url(r'^password/reset/complete/$','django.contrib.auth.views.password_reset_complete',name='auth_password_reset_complete'),
    url(r'^password/reset/done/$','django.contrib.auth.views.password_reset_done',name='auth_password_reset_done'),
    url(r'^register/$','register',name='registration_register'),
    url(r'^register/complete/$','/home/ale/woodstore/templates',{'template': 'registration/registration_complete.html'},name='registration_complete'),
    url(r'^accounts/', include('registration.urls')),
    
    #Contact
    url(r'^contact/', include('django_contactme.urls')),
    
    #Admin
    url(r'^admin/', include(admin.site.urls)),
    
    #SEO performed
    (r'^sitemap\.xml$','django.contrib.sitemaps.views.sitemap',{'sitemaps': sitemaps}),   
    (r'^BingSiteAuth\.xml$', direct_to_template, {'template': 'BingSiteAuth.xml', 'mimetype': 'application/xml'}),             
    (r'^googlea6b6b27bd10a1bde\.html$', direct_to_template, {'template': 'googlea6b6b27bd10a1bde.html'}),             
    (r'^robots\.txt$', include('robots.urls')),
     url(r'^tracking/', include('tracking.urls')),
     
     
     #Static and media files
     url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
     url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
     
     #RSS
     (r'^rssfeed/$', LatestEntriesFeed()),
     (r'^sitenews/$','coresales.views.sitenews'),
     (r'^atom/$', AtomSiteNewsFeed()),

)
handler404 = 'coresales.views.custom404View'
handler500 = 'coresales.views.custom500View'

from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
if settings.DEBUG:
    # add one of these for every non-static root you want to serve
    urlpatterns+= static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    # this take cares of static media (i.e. bundled in apps, and specified in settings)
    urlpatterns+= staticfiles_urlpatterns()
    